is there a way to read/write system environment variable through WMI
scripting ?
thanks.
Olivier
Sent via Deja.com http://www.deja.com/
Before you buy.
GetObject("WinMgmts:/root/cimv2:Win32_Environment.Name=""PATH""") fails
with "automation error"
In article <8hlal1$o8p$1...@nnrp1.deja.com>,
The following will get the instance back for you and print the value of the
setting:
Set PathObj =
GetObject("WinMgmts://./root/cimv2:Win32_Environment.Name='Path',UserName='<
SYSTEM>'")
wscript.echo PathObj.VariableValue
<mat...@my-deja.com> wrote in message news:8hlj86$uhm$1...@nnrp1.deja.com...
In article <hWs%4.101506$55.7...@news1.sttls1.wa.home.com>,
================================================
Dim SysEnvironment
SysEnvironment =
WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment\Path")
SysEnvironment = SysEnvironment & ";.\System;%SystemDrive%\Program
Files\OurStuff\Common Files\System"
nRtn = WshShell.RegWrite("HKLM\SYSTEM\ControlSet001\Control\Session
Manager\Environment\Path",SysEnvironment,"REG_EXPAND_SZ")
================================================<mat...@my-deja.com> wrote
in message news:8hlu7i$7vv$1...@nnrp1.deja.com...
// Get the class object itself
Set EnvVarClass = GetObject("WinMgmts://./root/cimv2:Win32_Environment")
// Make a new instance of that class
Set EnvVarInst = EnvVarClass.SpawnInstance_
// File in the key props and props of interest on that instance
EnvVarInst.Name = "TEST2"
EnvVarInst.UserName ="<SYSTEM>"
EnvVarInst.VariableValue="MyTestValue"
// Write the new instance in to WMI
EnvVarInst.Put_
Note, if you run this in a CMD shell, the variable does not show up
immediately. It will appear in the next CMD shell you run as these
variables are only read when the shell window initially starts.